package neu.soft.service.impl;

import lombok.extern.slf4j.Slf4j;
import neu.soft.constant.QueryType;
import neu.soft.query.InfoQueryFactory;
import neu.soft.vo.ResultBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * @author 李博
 * 通用的查询代理服务
 */
@Service
@Slf4j
public class InfoQueryProxyService {

    private InfoQueryFactory infoQueryFactory;

    @Autowired
    public InfoQueryProxyService(InfoQueryFactory infoQueryFactory) {

        this.infoQueryFactory = infoQueryFactory;
    }

    //统一查询方法，使用了服务定位模式，根据枚举类型选项相应的查询服务
    public ResultBean queryInfo(Map<String, Object> map) throws Exception {
        //枚举类型
        String enumName = (String) map.get("queryType");
        //获取查询类型的枚举类
        QueryType queryType = QueryType.valueOf(enumName);
        //获取查询条件
        Map<String, Object> objectMap = (Map<String, Object>) map.get("conditions");
        //调用查询服务
        return infoQueryFactory.getBaseInfoQuery(queryType).queryInfo(objectMap);
    }
}
